<template>
  <div><page-list :x-uri="uri" :x-tabs="tabs" :custom-components="custom" :search-options="searchOptions" :checkbox-item="false" :doactions="doactions"></page-list></div>
</template>
<script>
import PageList from '@public/template/page_list.vue';
import User from './components/user';
import Order from './components/order';
import { shortcutsLayterThreeMonth } from '@/common/js/const.js';

export default {
  components: {
    PageList
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/admin/finance/order/fail',
      tabs: [
        {
          title: '失败订单',
          uri: '/finance/order/fail',
          meta: {
            permission: 'finance.order.fail.list'
          }
        }
      ],
      custom: {
        user: User,
        order: Order
      },
      searchOptions: {
        time: {
          shortcuts: shortcutsLayterThreeMonth
        }
      },
      visible: false,
      doactions: [
        {
          title: '处理',
          callback: this.handle,
          meta: { permission: 'finance.order.fail.handle' }
        }
      ]
    };
  },
  methods: {
    handle: function({ row }) {
      this.$box
        .confirm('该操作将处理订单为已支付，并且处理后续服务，确认处理吗')
        .then(() => {
          this.$http.put(
            '/admin/finance/order/fail/' + row.order_no,
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
